-
-
Notifications
You must be signed in to change notification settings - Fork 18.4k
CLN GH22875 Replace bare excepts by explicit excepts in pandas/io/ #23004
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Hello @JustinZhengBC! Thanks for updating the PR.
Comment last updated on October 09, 2018 at 18:52 Hours UTC |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
looks good. small comment. ping on green.
pandas/io/pickle.py
Outdated
try: | ||
return try_read(path) | ||
except: | ||
except Exception: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you add a comment here
Codecov Report
@@ Coverage Diff @@
## master #23004 +/- ##
==========================================
+ Coverage 92.19% 92.19% +<.01%
==========================================
Files 169 169
Lines 50831 50911 +80
==========================================
+ Hits 46864 46939 +75
- Misses 3967 3972 +5
Continue to review full report at Codecov.
|
you can just push another commit, or generate a new hash |
pandas/io/pickle.py
Outdated
# reg/patched pickle | ||
try: | ||
return read_wrapper( | ||
lambda f: pc.load(f, encoding=encoding, compat=False)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there a reason you elminated this branch here? IIRC this was a perf issue (IOW try the compat=False), but I wrote this code a long time ago.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it appears that since then, someone has modified the load function so that compat isn't used at all.
pandas/pandas/compat/pickle_compat.py
Lines 189 to 214 in 5551bcf
def load(fh, encoding=None, compat=False, is_verbose=False): | |
"""load a pickle, with a provided encoding | |
if compat is True: | |
fake the old class hierarchy | |
if it works, then return the new type objects | |
Parameters | |
---------- | |
fh: a filelike object | |
encoding: an optional encoding | |
compat: provide Series compatibility mode, boolean, default False | |
is_verbose: show exception output | |
""" | |
try: | |
fh.seek(0) | |
if encoding is not None: | |
up = Unpickler(fh, encoding=encoding) | |
else: | |
up = Unpickler(fh) | |
up.is_verbose = is_verbose | |
return up.load() | |
except (ValueError, TypeError): | |
raise |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am skeptical, I put this here because of performance issues. Can you run the asv for the pickle tests? though it might be only a case of reading py2 in py3 which is affected by this, which we prob don't perf check.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also see if we actually hit this branch in any tests (meaning the try part is certainly hit, but the except is the question)
pandas/io/pickle.py
Outdated
# reg/patched pickle | ||
try: | ||
return read_wrapper( | ||
lambda f: pc.load(f, encoding=encoding, compat=False)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am skeptical, I put this here because of performance issues. Can you run the asv for the pickle tests? though it might be only a case of reading py2 in py3 which is affected by this, which we prob don't perf check.
pandas/io/pickle.py
Outdated
# reg/patched pickle | ||
try: | ||
return read_wrapper( | ||
lambda f: pc.load(f, encoding=encoding, compat=False)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you also see if we actually hit this branch in any tests (meaning the try part is certainly hit, but the except is the question)
Output of benchmark tests:
Both the remaining except blocks are necessary, as removing them will result in test failures. Upon further thought, I suppose it could be argued that the branch should remain in case someone modifies the load function later so that compat is used again. Should I put it back? |
yeah let's just put it back, but you can add a TODO that should see if can be removed safely., breaking pickle is not great and this is not super well tested. |
lgtm. merge on green. |
Thanks for the fixes @JustinZhengBC, good work. |
git diff upstream/master -u -- "*.py" | flake8 --diff
This is a resubmit of a previous PR I submitted that was approved (#22916). I tried to close and reopen to get a rebuild on travis but I couldn't reopen it because I had deleted my old fork (after accidentally pushing to master).